'''
Created on 15.12.2012

@author: felix
'''
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.Heuristic import Heuristic
from game import GameLogic
class CompleteFieldHeuristic(Heuristic):
    def __init__(self, weighting):
        Heuristic.__init__(self, weighting)
        self.fieldHeuristics = []
        
    def addHeuristic(self, heuristic):
        self.fieldHeuristics.append(heuristic)
    
    def inLoopHeuristic(self, field, action, color, nextColor, depth, position):
        pass
    
    def afterLoopHeuristic(self):
        pass
    
    def processInLoop(self, field, action, color, nextColor, depth, position):
        for h in self.fieldHeuristics:
            h.inLoopHeuristic(field, action, color, nextColor, depth, position)
            
    def prepare(self):
        pass
    
    def heuristic(self, field, action, color, nextColor, depth):
        for h in self.fieldHeuristics:
            h.prepare()
        for y in xrange(field.height):
            for x in xrange(field.width):
                if GameLogic.inRange(field, (x,y)):
                    self.processInLoop(field, action, color, nextColor, depth, (x,y))
        retVal = 0
        for h in self.fieldHeuristics:
            retVal += h.afterLoopHeuristic()
        return retVal